<?php
namespace app\admin\controller;
use think\Config;
use think\Controller;
use think\Request;
use think\Session;
use app\admin\controller\Auth;

class Base extends Controller
{
    public function _initialize()
    {
//        print_r(Session::get('logininfo'));               //获取用户登陆信息

        $maxTime = Config::get('session')['expire'];    //获取配置session过期时间
        $startTimt = Session::get('logininfo')['session_start_time'];       //获取登陆时间
        $isOut = time() - $startTimt;    //计算是否过期

        if($isOut>$maxTime){
            Session::clear();
        }
        if(!Session::get('logininfo'))
        {
            $this->error('请先登录系统','login/index');
        }



        $request=Request::instance();
        $status=$request->param('status');
        $con=$request->controller();
        $action=$request->action();
        $this->assign('con',$con);
        $this->assign('action',$action);
        $this->assign('status',$status);


        $auth=new Auth();
        if(isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"])=="xmlhttprequest"){
            $name=$con.'/'.$action;
        }else{
            // 正常请求的处理方式
            if($status){
                if($action){
                    $name=$con.'/'.$action.'/status/'.$status;
                }
                else{
                    $name=$con.'/'.$action;
                }
            }
            else{
                $name=$con.'/'.$action;
            }
        };

        $notCheck=array('Index/index','Admin/lst','Admin/logout','Business/countdays','Business/countweeks','Business/countmonth','Business/countyears');
        if(Session::get('logininfo')['group_id']!=2){
        if(!in_array($name, $notCheck)){
            if(!$auth->check($name,Session::get('logininfo')['uid'])){
                $this->error('没有权限',url('index/index'));
            }
        }

    }
    }

    public function returnjson($code,$info){
        return ['ECODE'=>$code,'MSG'=>$info];
    }


}
